The current invention generally relates to the field of x-ray and gamma ray imaging and more specifically to an imaging device used for collecting photons within a certain energy range or energy bins. Most often such imaging devices are referred to as “photon counting” devices and consist of a two dimensional array of pixels, each pixel comprising a detector element produced with lithography semiconductor techniques on a monolithic detector substrate for converting x/gamma rays into an electronic signal and a circuit element connected to the detector element for counting the incident x/gamma rays within a given energy range or several energy bins, utilizing in-pixel counters (thus the expression “photon counting”), or in other words counters for counting plural photons, such counters residing on each individual pixel circuit and for each pixel of the array. The prior art approach of in-pixel counters for counting incoming x/gamma ray hits into different energy bins has some advantages and several limitations which the current invention mitigates.